package com.usian.wemedia.controller;

import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmMaterialDto;
import com.usian.wemedia.WmMaterialControllerApi;
import com.usian.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController implements WmMaterialControllerApi {

    @Autowired
    private WmMaterialService wmMaterialService;
    public static final Short COLLECT_MATERIAL = 1;//收藏
    public static final Short CANCEL_COLLECT_MATERIAL = 0;//收藏

    /**
     * 素材库图片上传
     * @param multipartFile
     * @return
     */
    @Override
    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile multipartFile) {
        return wmMaterialService.upload(multipartFile);
    }

    /**
     * 素材库列表查询
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/list")
    public ResponseResult findList(@RequestBody  WmMaterialDto dto) {
        return wmMaterialService.findList(dto);
    }

    /**
     * 删除素材
     *
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    @Override
    public ResponseResult delMaterial(@PathVariable Integer id) {
        return wmMaterialService.delMaterial(id);
    }

    /**
     * 素材取消收藏
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancleCollectionMaterial(@PathVariable Integer id) {
        return wmMaterialService.updateStatus(id,(short)0);
    }

    /**
     * 素材收藏
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/collect/{id}")
    public ResponseResult collectionMaterial(@PathVariable Integer id) {
        return wmMaterialService.updateStatus(id,(short)1);
    }
}
